// JORGE FERNANDO GOMEZ
// 1259371
// 189631
// LEC A1
// MARTIN MÜLLER
// D02
// YANG LIU


#include <stdio.h>

#include "read.h"

#line 12 "read.c"

int inputFileLength = 0;
Line * LinePtr;

Line* initLines ( int size ) {
    LinePtr = calloc((size_t) size, sizeof(Line));
    return LinePtr;
}

Line* getLines ( void ) {
    return LinePtr;
}


/* readFile() takes a FILE * inputFile and uses fgets() to read lines
 * into Line * Lines.  Returns 0 when successful, or 1 if nothing was read. */
int readFile(Line * Lines, FILE * inputFile) {

    /* Go to beginning of file if not already there. */
    if ( ftell(inputFile) != 0 ) {
        fseek(inputFile, 0L, SEEK_SET);
    }

    /* Go through the whole file. */
    int currentLine = 0;
    while (fgets( Lines[currentLine].lineString, MAXLEN+1, inputFile)
                != NULL) {

        /* Remove trailing whitespace from each line. */
        chompim(Lines[currentLine].lineString);
        currentLine++;
    }

    /* Looks like nothing was read. */
    if ( !currentLine )
        return 1;

    return 0;
}
